<?php
function search($search,$get, $ext_button=[])
{
	$hr_write = 0; //是否输入hr;1输入,非1,不输入
	$hr = '<span style="display:inline;margin-left: 0px;margin-right: 10px;">-</span>' . "\r\n";
	$html = '<div class="demoTable">' . "\r\n";
	foreach ($search as $vo) {
		$html .= '<div class="layui-inline">' . "\r\n";
		switch ($vo['type']) {
			case 'select':
				$hr_write = 0;
				$laySearch = '';
				if(!empty(['lay-search'])) {
					$laySearch = 'lay-search';
				}
				$html .= '<div id="search_'.$vo['key'].'_div" class="layui-unselect layui-form-select">' . "\r\n";
				$html .= '<select '. $laySearch .' class="layui-input " id="search_' . $vo['key'] . '" name="' . $vo['key'] . '" lay-filter="filter_' . $vo['key'] . '">' . "\r\n";
				foreach ($vo['data'] as $lineVal => $lineKey) {
					if (!isset($get[$vo['key']]))
						$get[$vo['key']] = '0';
					if ($lineVal === $get[$vo['key']]) {
						$html .= '<option value="' . $lineVal . '" selected>' . $lineKey . '</option>' . "\r\n";
					} else {
						$html .= '<option value="' . $lineVal . '">' . $lineKey . '</option>' . "\r\n";
					}
				}
				$html .= '</select>' . "\r\n";
				$html .= '</div>' . "\r\n";
				break;
			case 'laydate':
				$hr_write++;
				$html .= '<input class="layui-input" name="' . $vo['key'] . '" id="search_' . $vo['key'] . '" autocomplete="off" placeholder="' . $vo['name'] . '">' . "\r\n";
				$html .= '<script>' . "\r\n";
				$html .= 'layui.use(\'laydate\', function(){' . "\r\n";
				$html .= 'var laydate = layui.laydate;' . "\r\n";
				$html .= 'search_' . $vo['key'] . ' = laydate.render({' . "\r\n";
				$html .= 'elem: "#search_' . $vo['key'] . '"' . "\r\n";

				foreach ($vo['data'] as $line) {
					$html .= ',' . $line['key'] . ':';
					if (!empty($line['type']) and $line['type'] == 'fun') $html .= $line['value'];
					else $html .= "'" . $line['value'] . "'";
				}
				$html .= '});' . "\r\n";
				$html .= '});' . "\r\n";
				$html .= '</script>' . "\r\n";
				break;
			case 'input_select':
				$hr_write = 0;

				$html .= '<div id="search_'.$vo['key'].'_div" class="layui-unselect layui-form-select">
                    <input type="hidden" name="' . $vo['key'] . '" id="search_'. $vo['key'] .'">
                    <select class="layui-input " id="select_'. $vo['key'] .'" lay-filter="input_select" lay-search>';
				foreach($vo['data'] as $line) {
					$html .= '<option value="'. $line['id'] .'">'. $line['name'] .'</option>' . "\r\n";
				}
				$html .= '</select></div>';
				$html .= '<script type="text/javascript">
                            
                        layui.use(["form"],function() {
                            var form = layui.form;
                            var $ = layui.$;
                                
                            form.on("select(input_select)", function(data) {
                                    
                                //给隐藏表单赋值
                                $("#search_' . $vo["key"].'").val(data.value);
                            });
                        });
                        </script>';
				break;
			default:
				$hr_write = 0;
				$html .= '<input class="layui-input" name="' . $vo['key'] . '" id="search_' . $vo['key'] . '" autocomplete="off" placeholder="' . $vo['name'] . '">' . "\r\n";
				break;
		}
		$html .= '</div> &nbsp;&nbsp;';
		if($hr_write == 1) $html .= $hr;
	}
	$html .= '<div class="layui-inline"><button class="layui-btn" data-type="reload">搜索</button></div>' . "\r\n";
	foreach($ext_button as $v) {
		$html .= '<button class="layui-btn" data-type="'. $v['type'] .'">'. $v['title'] .'</button>' . "\r\n";
	}

	$html .= '</div>' . "\r\n";
	return $html;
}
